package com.jilian.mydemo.modul.my.ui;

import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jilian.mydemo.MyApplication;
import com.jilian.mydemo.R;
import com.jilian.mydemo.base.BaseActivity;
import com.jilian.mydemo.base.CommonViewPagerAdapter;
import com.jilian.mydemo.modul.order.viewmodel.OrderViewModel;
import com.jilian.mydemo.views.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * 水工业绩
 */
public class HydraulicPerformanceActivity extends BaseActivity {
    private TextView tvOne;
    private TextView tvTwo;
    private TextView tvThree;
    private RelativeLayout rlOne;
    private RelativeLayout rlTwo;
    private RelativeLayout rlThree;
    private NoScrollViewPager viewPager;

    private List<Fragment> mFragmentList;
    private WeekFragment weekFragment;
    private MonthFragment monthFragment;
    private YearFragment yearFragment;
    private CommonViewPagerAdapter viewPagerAdapter;
    private OrderViewModel orderViewModel;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.addActivity(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyApplication.removeActivity(this);
    }

    @Override
    protected void createViewModel() {
        orderViewModel = ViewModelProviders.of(this).get(OrderViewModel.class);
    }

    @Override
    public int intiLayout() {
        return R.layout.activity_hydraulicperformance;
    }

    @Override
    public void initView() {
        setNormalTitle("水工业绩", v -> finish());
        tvOne = (TextView) findViewById(R.id.tv_one);
        tvTwo = (TextView) findViewById(R.id.tv_two);
        tvThree = (TextView) findViewById(R.id.tv_three);
        rlOne = (RelativeLayout) findViewById(R.id.rl_one);
        rlTwo = (RelativeLayout) findViewById(R.id.rl_two);
        rlThree = (RelativeLayout) findViewById(R.id.rl_three);
        viewPager = (NoScrollViewPager) findViewById(R.id.viewPager);
        mFragmentList = new ArrayList<>();
        weekFragment = new WeekFragment();
        monthFragment = new MonthFragment();
        yearFragment = new YearFragment();
        mFragmentList.add(weekFragment);
        mFragmentList.add(monthFragment);
        mFragmentList.add(yearFragment);
        viewPagerAdapter = new CommonViewPagerAdapter(getSupportFragmentManager(), mFragmentList);
        viewPager.setAdapter(viewPagerAdapter);


    }

    @Override
    public void initData() {
    }


    @Override
    public void initListener() {
        tvOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewPager.setCurrentItem(0);
            }
        });
        tvTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewPager.setCurrentItem(1);
            }
        });
        tvThree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewPager.setCurrentItem(2);
            }
        });
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                switch (i) {
                    case 0:
                        tvOne.setTextColor(getResources().getColor(R.color.color_main_title));
                        tvTwo.setTextColor(getResources().getColor(R.color.color_hint));
                        tvThree.setTextColor(getResources().getColor(R.color.color_hint));
                        rlOne.setVisibility(View.VISIBLE);
                        rlTwo.setVisibility(View.INVISIBLE);
                        rlThree.setVisibility(View.INVISIBLE);
                        break;
                    case 1:
                        tvOne.setTextColor(getResources().getColor(R.color.color_hint));
                        tvTwo.setTextColor(getResources().getColor(R.color.color_main_title));
                        tvThree.setTextColor(getResources().getColor(R.color.color_hint));
                        rlOne.setVisibility(View.INVISIBLE);
                        rlTwo.setVisibility(View.VISIBLE);
                        rlThree.setVisibility(View.INVISIBLE);
                        break;
                    case 2:
                        tvOne.setTextColor(getResources().getColor(R.color.color_hint));
                        tvTwo.setTextColor(getResources().getColor(R.color.color_hint));
                        tvThree.setTextColor(getResources().getColor(R.color.color_main_title));
                        rlOne.setVisibility(View.INVISIBLE);
                        rlTwo.setVisibility(View.INVISIBLE);
                        rlThree.setVisibility(View.VISIBLE);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });

    }
}
